package cn.xopencode.scoreservice.dal.mysql.mapper.demand;


import cn.xopencode.common.framework.util.DateUtil;
import cn.xopencode.common.framework.vo.SortingField;
import cn.xopencode.mybatis.core.query.QueryWrapperX;
import cn.xopencode.mybatis.core.util.PageUtil;
import cn.xopencode.score.api.rpc.demand.dto.ScoreReqDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreRespDTO;
import cn.xopencode.scoreservice.dal.mysql.dataobject.demand.ScoreAllDO;
import cn.xopencode.scoreservice.dal.mysql.dataobject.demand.ScoreDO;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestPageReqDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface ScoreMapper extends BaseMapper<ScoreDO> {

    /**
     *
     * @return 所有员工每月总分数情况，并按照日期倒叙展示
     */
    default IPage<ScoreDO> selectPage(ScoreReqDTO scoreReqDTO) {
        return selectPage(PageUtil.build(scoreReqDTO),
                new QueryWrapperX<ScoreDO>().eqIfPresent("emp_id", scoreReqDTO.getEmpId()));
    }


    default ScoreDO selectScoreFromDate(String empId, Date updateTime) {
        System.out.println("data"+DateUtil.format(updateTime,"yyyy-MM-dd"));
        return selectOne(new QueryWrapperX<ScoreDO>().eqIfPresent("emp_id", empId)
                .likeIfPresent("update_time", DateUtil.format(updateTime,"yyyy-MM-dd")+"%"));
    }

    default ScoreDO selectByEmpId(String empId){
        return (ScoreDO) selectList(new QueryWrapperX<ScoreDO>().eq("emp_id", empId));
    }


    default  List<ScoreAllDO> selectAllByEmpId(String empId)
    {
        return selectAllId(empId);
    }


    default ScoreDO selectById(String id){
        return selectOne(new QueryWrapperX<ScoreDO>().eqIfPresent("id", id));
    }

    void updateSuggestScore(@Param("scoreDO")ScoreDO scoreDO);

    void updateActivityScore(@Param("scoreDO")ScoreDO scoreDO);

    void updateAccidentScore(@Param("scoreDO")ScoreDO scoreDO);

    void clearAccidentScore(@Param("scoreDO")ScoreDO scoreDO);

    void insertScore(@Param("scoreDO")ScoreDO sdo);

    List<ScoreAllDO> selectAllId(String empId);
}
